/**
 * Copyright (C), 2019
 * FileName: CommonFrameFragment
 * Author: Administrator
 * Date: 2019/1/29 11:34
 * Description: 常用框架fragement
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package com.example.demolearn_1.fragement;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.demolearn_1.R;
import com.example.demolearn_1.base.BaseFragment;

import org.jetbrains.annotations.Nullable;


/**
 * @ClassName: CommonFrameFragment
 * @Description: java类作用描述
 * @Author: Administrator
 * @Date: 2019/1/29 11:34
 */
public class ThirdPartyFragment extends BaseFragment {
    private TextView title;
    private ListView mListView;
    private String[] mDataList;
    private ThirdPartyFragment.CommonFrameFragmentAdapter mAdatpter;

    @Override
    protected View initView() {
        View view = View.inflate(mContext, R.layout.fragment_demo, null);
        mListView = (ListView) view.findViewById(R.id.lv_list);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                String data = mDataList[position];
//                if (data.toLowerCase().equals("自动升级")) {
//                    Intent intent = new Intent(mContext, AutoUpdateActivity.class);
//                    mContext.startActivity(intent);
//                }
//                // 点击位置的显示
//                Toast.makeText(mContext, "data==" + data, Toast.LENGTH_SHORT).show();
            }
        });

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    protected void initData(){
        mDataList = new String[]{"自动升级"};

        mAdatpter = new ThirdPartyFragment.CommonFrameFragmentAdapter(mContext,mDataList);
        mListView.setAdapter(mAdatpter);
    }

    private class CommonFrameFragmentAdapter extends BaseAdapter {

        private final Context mContext;
        private final String[] mDataList;

        public CommonFrameFragmentAdapter(Context mContext, String[] mDataList) {
            this.mContext = mContext;
            this.mDataList = mDataList;
        }

        @Override
        public int getCount() {
            return mDataList.length;
        }

        @Override
        public Object getItem(int position) {
            return mDataList[position];
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView textView = new TextView(mContext);
            textView.setPadding(10,10,0,10);
            textView.setTextColor(Color.BLACK);
            textView.setTextSize(20);
            textView.setText(mDataList[position]);
            return textView;
        }
    }


}
